package com.ultrasoft.farmasoft.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ultrasoft.farmasoft.domain.Article;
import com.ultrasoft.farmasoft.domain.Section;
import com.ultrasoft.farmasoft.repository.ArticleDao;
import com.ultrasoft.farmasoft.repository.SectionDao;
@Service
public class PortadaDepartmentsServiceImpl implements PortadaDepartmentsService {
	
	private ArticleDao articleDao;
	private SectionDao sectionDao;
	
	//ARTICLE
	@Autowired
	public PortadaDepartmentsServiceImpl(ArticleDao articleDao,SectionDao sectionDao){
		this.articleDao 					= articleDao;
	    this.sectionDao						= sectionDao;
	}
	
	@Transactional(readOnly = true)
	public List<Article> getArticleList(){
		return articleDao.getArticleList();
	}

	@Transactional(readOnly = true)
	public List<Article> getArticleList(Integer idArticle) {
		return articleDao.getArticleList(idArticle);
	}

	@Transactional(readOnly = true)
	public List<Article> getArticleListWithIdRegion(Integer idRegion) {
		return articleDao.getArticleListWithIdRegion(idRegion);
	}
	
	@Transactional(readOnly = true)
	public List<Article> getArticleListWithIdRegionActive(Integer idRegion, boolean active) {
		return articleDao.getArticleListUserWithIdRegionActive(idRegion, active);
	}

	@Transactional(readOnly = true)
	public List<Article> getArticleListWhitUserId(Integer createUserId) {
		return articleDao.getArticleListUser(createUserId);
	}

	@Transactional(readOnly = true)
	public Article searchArticleByID(Integer idArticle) {
		return articleDao.findArticleByID(idArticle);
	}
	
	@Transactional(readOnly = true)
	public List<Article> getArticleDistintRegionId(){
		return articleDao.getArticleDistintRegionId();
	}
	
	@Transactional(readOnly = true)
	public List<Article> getArticleDistinctRegionRegains(Integer idRegion){
		return articleDao.getArticleDistinctRegionRegains(idRegion);
	}
	
	@Transactional
	public void removeArticle(Article article){
		articleDao.remove(article);
	}    
	@Transactional
	public void addArticle(Article country){
		articleDao.add(country);
	}
	
	@Transactional
	public void updateArticle(Article country) {
		articleDao.update(country);
	}

	//SECTION
	@Transactional(readOnly = true)
	public List<Section> getSectionList(){
		return sectionDao.getSectionList();
	}
	
	@Transactional(readOnly = true)
	public List<Section> getSectionList(Integer idSection) {
		return sectionDao.getSectionList(idSection);
	}

	@Transactional(readOnly = true)
	public List<Section> getSectionListWithIdArticle(Integer idArticle) {
		return sectionDao.getSectionListWithIdArticle(idArticle);
	}
	
	@Transactional(readOnly = true)
	public Section searchSectionByID(Integer idSection) {
		return sectionDao.findSectionByID(idSection);
	}

	@Transactional
	public void removeSection(Section section){
		sectionDao.remove(section);
	}    
	@Transactional
	public void addSection(Section section){
		sectionDao.add(section);
	}
	
	@Transactional
	public void updateSection(Section section) {
		sectionDao.update(section);
	}
	
	@Transactional(readOnly = true)
	public List<Section> getSectionListWithIdArticleActive(Integer idArticle, boolean active) {
		return sectionDao.getSectionListArticleWithIdArticleActive(idArticle, active);
	}
	
	@Transactional(readOnly = true)
	public List<Section> getSectionWithRegionId(Integer idRegion, boolean active){
		return sectionDao.getSectionWithRegionId(idRegion,active);
	}
	
	@Transactional(readOnly = true)
	public List<Section> getListDistictSectionWithRegionId(Integer idRegion, boolean active){
		return sectionDao.getListDistictSectionWithRegionId(idRegion, active);
	}
}
